/*****************************************************
** Author: 
** Date: 2019-11-04
*
*****************************************************/

#include "gpio.h"

/**
 * @brief
 * @param  None
 * @retval None
 */
static int gpio_dir(lua_State* L)
{
    int dir  = luaL_checkinteger(L, -1);
    int gpio = luaL_checkinteger(L, -2);
    
    lua_log_dbg("set gpio %d dir %d", gpio, dir);
    print_lua_stack(L, "gpio_dir");
    return 0;
}

static int gpio_set(lua_State* L)
{
    int level = luaL_checkinteger(L, -1);
    int gpio  = luaL_checkinteger(L, -2);

    lua_log_dbg("set gpio %d level %d", gpio, level);
    print_lua_stack(L, "gpio_set");
    return 0;
}

static int gpio_get(lua_State* L)
{
    int gpio  = luaL_checkinteger(L, -1);

    int level = 1;
    lua_pushinteger(L, level);
    lua_log_dbg("get gpio %d level %d", gpio, level);
    print_lua_stack(L, "gpio_get");
    return 1;
}

int luaopen_gpio(lua_State *l)
{
    const char *lib_name = "gpio";
    luaL_Reg gpio[] = {
        {"dir",     gpio_dir},
        {"set",     gpio_set},
        {"get",     gpio_get},
        {NULL, NULL}
    };
    luaL_openlib(l, lib_name, gpio, 0);
    print_lua_stack(l, "open lua 'gpio'");

    lua_log_inf("open lua 'gpio' success");
    return LUA_ARCH_OK;
}

int luaclose_gpio(lua_State *l)
{
    lua_log_inf("close lua 'gpio'");
    return LUA_ARCH_OK;
}

/* End of file */



